;
// 探空曲线
(function () {
    var tLogp = {
        init: function () {
            $.IDate(".date-panel2", {
                query: function query() {}
            });
            this.bindEvt();
        },
        query: function () {
        	//this.getLatestTime();
            this.getTlogpImg();
            this.getTlogpData();
        },
        // 获取最新起报时间
        getLatestTime: function() {
        	var that = this;
        	var stationId = $(".city-content li.active").data('city');
        	var param = {
        		pcode: 'HIGH-TLOGP',
        		area: 'AFSH',
                height: 0,
                stationId: stationId
        	};
        	$.ajax({
        		url: CafeJS.CXT+'/analysis/getWeatherLatestTime.do',
        		type: 'GET',
        		dataType: 'json',
        		async: false,
        		data: param
        	}).done(function(res){
        		if (res.success && res.params.data) {
        			var latestTime = dateUtil.convertStringToDate7(res.params.data,'yyyy-MM-dd hh:mm');
        			$("#queryDate").IDatePicker().setVal(latestTime);
        		}
        	})
        },
        // 获取图片数据
        getTlogpImg: function () {
            var queryTime = $("#queryDate").IDatePicker().getVal() + ":00";
            queryTime = new Date(queryTime).format('yyyyMMddhhmmss');
            var stationId = $(".city-content li.active").data('city');
            var params = {
                queryTime: queryTime,
                pcode: 'TLOGP-AFSH',
                stationId: stationId
            };
            $.getJSON(CafeJS.CXT + "analysis/getTlogpProduct.do", params, function (res) {
                if (res.success) {
                    var dataArr = JSON.parse(res.params.data);
                    for (var i = 0; i < dataArr.length; i++) {
                        var proObj = dataArr[i];
                        var name = $(".city-content li.active").text();
                        $(".content-right-img1").html("<li><img src=\"" + proObj.url + "\"></li>");
                        $(".content-right-list .date").html(proObj.timeStr.split(' ')[0]);
                        $(".content-right-list .timet").html(proObj.timeStr.split(' ')[1]);
                        $(".content-right .title").html(name + ' ' + proObj.timeStr + ' ' + 'T-LogP探空曲线');
                    };
                    $(".content-right-img1>li").eq($(".city-content .active").index()).show().siblings().hide();
                };
            });
        },
        // 获取表格数据
        getTlogpData: function () {
            var that = this;
            var queryTime = $("#queryDate").IDatePicker().getVal() + ":00";
            queryTime = new Date(queryTime).format('yyyyMMddhhmmss');
            //queryTime = '20190318080000';
            var stationId = $(".city-content li.active").data('city');
            //stationId = '58367';
            var params = {
                queryTime: queryTime,
                area: 'AFSH',
                stationId: stationId,
                agings: '000'
            };
            $.getJSON(CafeJS.CXT + "analysis/getTlogpData.do", params, function (res) {
                if (res.success) {
                    var dataArr = res.params.data;
                    for (var key in dataArr) {
                        $('.tLogp-' + key).html(dataArr[key]);
                    };
                };
            });
        },
        bindEvt: function () {
            var that = this;
            // 站点切换
            $(".city-content").on("click", 'li', function () {
                $(this).addClass("active").siblings().removeClass("active");
                var name = $(".city-content li.active").text();
                var zd = $(".city-content li.active").data('city');
                $(".name").html(name);
                $(".code").html(zd);
                that.query();
            });
            $(".content-left-title2").click(function () {
                $(this).parent().siblings().find(".dq").hide();
                $(this).parent().siblings().find("i").removeClass("active");
                if ($(this).next(".dq:hidden").length === 0) {
                    $(this).next(".dq").hide();
                } else {
                    $(this).next(".dq").show();
                };
                if ($(this).find("i").hasClass("active")) {
                    $(this).find("i").removeClass("active");
                } else {
                    $(this).find("i").addClass("active");
                };
            });
            $('.date-panel2').off('click').on('click', '.btn-forward', function (e) { // 日期向前
                e.stopPropagation();
                $("#queryDate").IDatePicker().toForward();
            }).on('click', '.btn-backward', function (e) { // 日期向后
                e.stopPropagation();
                $("#queryDate").IDatePicker().toBackward();
            }).on('click', ".btn-search", function (e) { // 搜索
				e.stopPropagation();
				that.query();
			}).on('click', ".btn-newest", function (e) { // 最新
                e.stopPropagation();
                $("#queryDate").IDatePicker().toNewest();
                that.query();
            });
            $(".city-content li.active").click();
        },
    }
    tLogp.init();
})()